let path = require('path')
let HtmlWebpackPlugin = require('html-webpack-plugin')
let webpack = require('webpack')
let Happypack = require('happypack')

module.exports = {
    mode:'development',
    entry:'./src/index.js',
    devServer:{
        port:3000,
        open:true,
        contentBase:'./dist'
    },
    module:{
        noParse:/jquery/,
        rules:[
            {
            test:/\.css$/,
            // use:'Happypack/loader?id=css'
            // use:['style-loader','css-loader']
            use:'Happypack/loader?id=css'
            },
            {
                test:/\.js$/,
                exclude:/node_modules/,
                include:path.resolve('src'),
                // 优化项  排除依赖，只打包src的js
                use:'Happypack/loader?id=js'
                
            }
        ]
    },
    output:{
        filename:'bundle.js',
        path:path.resolve(__dirname,'dist')
    },
    plugins:[
        new Happypack({
            id:'css',
            use:['style-loader','css-loader']
        }),
        new Happypack({
            id:'js',
            use:[{
                loader:'babel-loader',
                options:{
                    presets:[
                        '@babel/preset-env',
                        '@babel/preset-react'
                    ]
                }
            }]
        }),
        new webpack.DllReferencePlugin({
            manifest:path.resolve(__dirname,'dist','manifest.json')

        }),
        new webpack.IgnorePlugin(/\.\/locale/,/moment/),
        new HtmlWebpackPlugin({
            template:'./pubilc/index.html'
        })
    ]
}